package com.system.jfm;

import com.system.Models.Admin;
import com.system.jfm.MainTables.ChangeAdminPassword;
import com.system.jfm.MainTables.StudentInfo;
import com.system.jfm.MainTables.StudentScore;
import com.system.tools.MyFunction;

import javax.swing.*;
import java.awt.*;
import java.sql.SQLException;

public class MainTable extends JFrame {

    // 三个主面板
    StudentInfo studentInfoTable;
    StudentScore studentScoreTable;
    ChangeAdminPassword changeAdminPasswordTable;
    JTabbedPane tabbedPane;
    Admin admin;

    private void updateTables() throws SQLException {

        this.studentInfoTable.initTable();
        this.studentScoreTable.initTable();

    }

    MainTable(Admin admin) throws SQLException {
        this.admin=admin;
        initFrame();
    }
    private void initFrame() throws SQLException {
        // 窗口设置
        Image iconImage = Toolkit.getDefaultToolkit().getImage("src/com/system/image/icon.png");
        this.setIconImage(iconImage);
        this.setTitle("StuHub | 主界面");
        this.setSize(650,500);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.getContentPane().setBackground(Color.white);

        // 左侧导航卡
        tabbedPane = new JTabbedPane(JTabbedPane.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);
        tabbedPane.setBounds(0,0,120,500);

        MyFunction updateTableFunc = ()->{this.updateTables();};
        studentInfoTable   = new StudentInfo(updateTableFunc);
        studentScoreTable = new StudentScore();
        MyFunction closeFunc = ()->{this.setVisible(false);};
        changeAdminPasswordTable = new ChangeAdminPassword(admin,closeFunc);

        // 创建第一个选项卡的内容
        JPanel tab1Panel = new JPanel();
        tab1Panel.add(studentInfoTable);

        // 创建第二个选项卡的内容
        JPanel tab2Panel = new JPanel();
        tab2Panel.add(studentScoreTable);

        // 创建第三个选项卡的内容
        JPanel tab3Panel = new JPanel();
        tab3Panel.add(changeAdminPasswordTable,BorderLayout.CENTER);

        // 将选项卡添加到选项卡面板中，并指定每个选项卡的标题
        tabbedPane.addTab("学生信息", tab1Panel);
        tabbedPane.addTab("学生成绩", tab2Panel);
        tabbedPane.addTab("更改密码", tab3Panel);

        this.add(tabbedPane);

        this.setVisible(true);
    }
}
